package ljx;
import java.sql.*;

public class JdbcUtils {
    private static String url = null;
    private static String Driver=null;
    private static String username=null;
    private static String password=null;
    static {
        //；连接db.properties数据
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //获取数据库连接的对象
    public static Connection getConnection() throws SQLException{
        return DriverManager.getConnection("jdbc:mysql://localhost:3306/myself?characterEncoding=UTF-8&useSSL=true", "root", "123456");
    }

    //释放资源
    public static void relesse(Connection conn, Statement st,ResultSet rs ){
        if(rs!=null){
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            rs=null;
        }
        if(st!=null){
            try {
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            st=null;
        }
        if(conn!=null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            conn=null;
        }
    }

}
